62
Beginner’s Guide to Code Algorithms
62
STEP 21 continued
Next j
Next i
snapshotc = cantbelist
‘ * Step 2 make a list of all the cells that have 2 values
‘ * note: this bit of code is from the love-locked pair algorithm
For i = 1 To 9
For j = 1 To 9
cantbelistcount(i, j) = 0
For k = 1 To 9
If cantbelist(i, j, k) <> 0 Then
cantbelistcount(i, j) = cantbelistcount(i, j) + 1
End If
Next k
If sbox(i, j) = ““ And cantbelistcount(i, j) = 7 Then
putnumberpresent(i, j) = ““
For putnumber = 1 To 9
If findincantbelist(putnumber, i, j) = 0 Then
putnumberpresent(i, j) = putnumberpresent(i, j) & putnumber
End If
Next putnumber
End If
Next j
Next i
STEP 22
Next two steps to use each two-value cell and try out one of the values to see if Set
1 = Set 2.
:
‘ * Step 3 & 4 Try the 2 values, find values for empty cells for each, check for keepers
(Set 1 = Set 2) and update grid
For i = 1 To 9
For j = 1 To 9
If putnumberpresent(i, j) <> ““ Then
‘ build S1
Cells(i, j) = Left(putnumberpresent(i, j), 1)
sbox(i, j) = Cells(i, j)
Call RefreshCantbelist
Call fillemptycells
For k = 1 To 9
For l = 1 To 9
s1(k, l) = Cells(k, l)
Next l
Next k
‘ restore snapshot
For k = 1 To 9
For l = 1 To 9
Cells(k, l) = snapshot(k, l)
sbox(k, l) = snapshot(k, l)
Next l